package org.csc.sss.util;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class PasswordEncoderUtils {

    /**
     * 密码加密
     * @param password
     * @return
     */
    public static String passwordEncoder(String password) {

        return new BCryptPasswordEncoder().encode(password.trim());
    }

    /**
     * 判断密码是否正确
     * @param rawPassword 原始密码
     * @param encodedPassword 加密后的密码
     * @return
     */
    public static Boolean passwordMatches(CharSequence rawPassword, String encodedPassword) {

        return new BCryptPasswordEncoder().matches(rawPassword, encodedPassword);
    }

    public static void main(String[] args) {
        System.out.println(passwordMatches("1", "$2a$10$cte7Uys3rmZewMAn03mq4.YpwLAnm0p25YhhyP81YJ/SS3SSB8oFC"));
    }

}
